<?php
/* @var $this TenderController */
/* @var $model Tender */
/* @var $form CActiveForm */
Yii::app()->clientScript->registerScript('noweekend', "
$('#noweekend').click(function(event){
	var s_time = $('#Tender_saletime').val();
	if(!s_time)
		return;
	else
		var s_date = new Date(s_time);
	if($('#noweekend').attr('checked')){
		s_date.setDate(s_date.getDate()+5);
	}else{
		s_date.setDate(s_date.getDate()+7);
	}
	var year = s_date.getFullYear();
	var month = s_date.getMonth()+1; //js从0开始取
	var date = s_date.getDate(); 
	$('#Tender_endtime').val(year+'-'+month+'-'+date); 
});
");
?>
<script language="type/javascript">
function autodate(){
	var s_t = $('#Tender_saletime').val();
	var s_d = new Date(s_time);
	var o_d = new Date(s_time);
	if($('#noweekend').attr('checked')){
		s_d.setDate(s_d.getDate()+5);
	}else{
		s_d.setDate(s_d.getDate()+7);
	}
	var year = s_d.getFullYear();
	var month = s_d.getMonth()+1; //js从0开始取
	var date = s_d.getDate(); 
	$('#Tender_endtime').val(year+'-'+month+'-'+date); 
	
	var o_year = o_d.getFullYear();
	var o_month = o_d.getMonth()+1; //js从0开始取
	var o_date = o_d.getDate(); 
	o_d.setDate(o_d.getDate()+20);
	$('#Tender_opentime').val(o_year+'-'+o_month+'-'+o_date+' 10:00'); 
	$('#ui-datepicker-div').hide();
}
</script>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'tender-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note"><span class="required">*</span>号为必填项</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'pid'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
			'name'=>'Tender[pid]',
			'id'=>'Tender_pid',
			'value'=> $model->isNewRecord ? '' : $model->project->projectname,
			'sourceUrl' => array('project/getItems'),
			//'source' => array('1','2','11'),
			'options'=>array(
				'minLength'=>1,
				'autoFill'=>true,
				'select'=>'js:function(event,ui){
					$("#Tender_pid").select();
					$("#Tender_tendererid").val(ui.item.tenderer)
				}',
			),
			'htmlOptions'=>array(
				'size'=>60,
				'maxlength'=>256
			),
		));
		?>
		<?php echo $form->error($model,'pid'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'tendername'); ?>
		<?php echo $form->textField($model,'tendername',array('size'=>60,'maxlength'=>256)); ?>
		<?php echo CHtml::label(Yii::t('tender','Ifretender'),'re'); ?>
		<?php echo $this->renderPartial('_lists',array('smodel'=>$smodel,'model'=>$model)); ?>
		<?php echo $form->error($model,'tendername'); ?>
	</div>

	<?php echo $form->hiddenField($model,'rid');?>

	<div class="row">
		<?php echo $form->labelEx($model,'tendererid'); ?>
		<?php echo $form->dropDownList($model,'tendererid',CHtml::listData($tender,'tendererid','name')); ?>
		<?php echo $form->error($model,'tendererid'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'mode'); ?>
		<?php echo $form->dropDownList($model,'mode',Tender::itemAlias('ModeStatus')); ?>
		<?php echo $form->error($model,'mode'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'userid'); ?>
		<?php echo $form->dropDownList($model,'userid',User::model()->getOperationUser()); ?>
		<?php echo $form->error($model,'userid'); ?>
	</div>
	
	<div class="row fl">
		<?php echo $form->labelEx($model,'saletime'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>'Tender[saletime]',
            'value' => $model->isNewRecord ? date('Y-m-d') : $model->saletime,
            // additional javascript options for the date picker plugin
            'options'=>array(
                'showAnim'=>'fold',
                'dateFormat' => "yy-mm-dd",
            ),
            'htmlOptions'=>array(
                'style'=>'',
				'onchange'=>'autodate()',
            ),
        ));
		?>
		<?php echo $form->error($model,'saletime'); ?>
	</div>
	
	<div class="row fl">
		<?php echo $form->labelEx($model,'endtime'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>'Tender[endtime]',
            'value' => $model->isNewRecord ? date('Y-m-d',time()+432000) : $model->endtime,
            // additional javascript options for the date picker plugin
            'options'=>array(
                'showAnim'=>'fold',
                'dateFormat' => "yy-mm-dd",
            ),
            'htmlOptions'=>array(
                'style'=>''
            ),
        ));
		?>
		<?php echo $form->error($model,'endtime'); ?>
	</div>
	
	<div class="row fl">
		<?php echo Yii::t('tender','Noweekend');?>
		<?php echo CHtml::checkBox('noweekend', true); ?>
	</div>
	<div class="clear"></div>
	<div class="row">
		<?php echo $form->labelEx($model,'opentime'); ?>
		<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
			$this->widget('CJuiDateTimePicker',array(
				'name'=>'Tender[opentime]',
				'value' => $model->isNewRecord ? date('Y-m-d H:i',mktime(10,0,0,date('m'),date('d')+20,date('Y'))) : $model->opentime,
				'mode'=>'datetime',
				// additional javascript options for the date picker plugin
				'options'=>array(
					'showAnim'=>'fold',
					'dateFormat' => "yy-mm-dd",
			    ),
				'htmlOptions'=>array(
					'style'=>''
				),
			));
		?>
		
		<?php echo $form->error($model,'opentime'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('tender','Create') : Yii::t('tender','Save')); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
